
package com.insigma.business.qrcode.merchant.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.merchant.dao.CareWelfareMerchantStreetDao;
import com.insigma.business.qrcode.merchant.dao.CareWelfareMerchantStreetRelDao;
import com.insigma.business.qrcode.merchant.entity.CareWelfareMerchantStreetDO;
import com.insigma.business.qrcode.merchant.entity.CareWelfareMerchantStreetRelDO;
import com.insigma.business.qrcode.merchant.service.CareWelfareMerchantStreetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("careWelfareMerchantStreetService")
public class CareWelfareMerchantStreetServiceImpl implements CareWelfareMerchantStreetService {

    @Autowired(required = false)
    private CareWelfareMerchantStreetDao careWelfareMerchantStreetDao;

    @Autowired(required = false)
    private CareWelfareMerchantStreetRelDao careWelfareMerchantStreetRelDao;

    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<CareWelfareMerchantStreetDO> search(final CareWelfareMerchantStreetBSearcher careWelfareMerchantStreetBSearcher) {
        return careWelfareMerchantStreetDao.search(careWelfareMerchantStreetBSearcher);
    }
   
    @Override
    public CareWelfareMerchantStreetDO get(final String id){
        return careWelfareMerchantStreetDao.get(id);
    }

    
    @Override
    public Integer insert(final CareWelfareMerchantStreetDO careWelfareMerchantStreetDO){
        careWelfareMerchantStreetDO.setId(sequenceGenerator.genKey(SequenceNameConstant.CARE_WELFARE_MERCHANT_STREET_ID));
        return careWelfareMerchantStreetDao.insert(careWelfareMerchantStreetDO);
    }

    
    @Override
    public Integer update(final CareWelfareMerchantStreetDO careWelfareMerchantStreetDO){
        return careWelfareMerchantStreetDao.update(careWelfareMerchantStreetDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        careWelfareMerchantStreetRelDao.deleteByStreetId(id);
        return careWelfareMerchantStreetDao.delete(id,modifierType,modifierId);
    }

    @Override
    public CareWelfareMerchantStreetDO getByMerchantId(String merchantId) {
        CareWelfareMerchantStreetRelDO byMerchantId = careWelfareMerchantStreetRelDao.getByMerchantId(merchantId);
        if (byMerchantId != null) {
            CareWelfareMerchantStreetDO careWelfareMerchantStreetDO = careWelfareMerchantStreetDao.get(byMerchantId.getStreetId());
            return careWelfareMerchantStreetDO;
        }
        return null;
    }

}
